********************************************************************************
*Replication do File 
*Paper: Whats the price of Freedom? 
*date: 13 Dic 2021
********************************************************************************

use data.dta, clear

************************************************************************************
*Programa
capture program drop tablasj3
program define tablasj3
syntax, title(string) input(name) colum(integer) 


end

capture program drop tablasj4
program define tablasj4
syntax, title(string) input(name) colum(integer) 


end

capture program drop tabletab
program define tabletab
syntax, title(string) input(name) 
end

capture program drop estadd_WTP
program estadd_WTP, eclass 
tempname wtp 
tempname wtp_ll
tempname wtp_ul
mat `wtp' = r(wtp)
mat `wtp_ll' = `wtp'[2, 1..3]
mat `wtp_ul' = `wtp'[3, 1..3]
  ereturn matrix wtp = `wtp'
  ereturn matrix wtp_ll = `wtp_ll' 
  ereturn matrix wtp_ul = `wtp_ul'
 end
  
***********************************************************************************/
#delimit ;
local opts1 style(tex)  varlabels(_cons Constant fulltime_flex "Full Time Flex" parttime_noflex "Part Time no Flex" parttime_flex "Part Time Flex") cells(b(star fmt(%9.2f)) se(par))  stats(N, fmt(%9.3g) label("N"))
	 label collabels(none) msign(--) nolz varwidth(1) modelwidth(20) starlevels(* 0.10 ** 0.05 *** 0.01);	 
local opts2 style(tex)  varlabels(_cons Constant fulltime_flex "Full Time Flex" parttime_noflex "Part Time no Flex" parttime_flex "Part Time Flex") cells(wtp(fmt(%9.2f)) wtp_ll(fmt(%9.2f)) wtp_ul(fmt(%9.2f)))   stats(N, fmt(%9.3g) label("N"))
	label collabels(none) msign(--) nolz varwidth(1) modelwidth(20) starlevels(* 0.10 ** 0.05 *** 0.01);	 
	 #delimit cr

***********************************************************************************/
*Stats
*Table 5
gen T = fulltime_noflex+ 2*fulltime_flex+ 3*parttime_noflex + 4* parttime_flex
label define T 1 "Full-time no flex" 2 "Full time flex" 3 "Part-time no flex" 4 "Part-time flex"
label value T T

*table T, stats(mean sel freq)

gen first=1 if j==1 & (orden1==1 |orden1==2) 
replace first=1 if j==2 & (orden1==3|orden1==4)
replace first=1 if j==3 & (orden1==5|orden1==6)
replace first=0 if first==.
tab seleccion first if seleccion==j

gen middle=1 if j==1 & (orden1==3 |orden1==5) 
replace middle=1 if j==2 & (orden1==1|orden1==6)
replace middle=1 if j==3 & (orden1==2|orden1==4)
replace middle=0 if middle==.
tab seleccion middle if seleccion==j

gen last =1 if j==1 & (orden1==4 |orden1==6) 
replace last=1 if j==2 & (orden1==2|orden1==5)
replace last=1 if j==3 & (orden1==1|orden1==3)
replace last=0 if last==.
tab seleccion last if seleccion==j


*TABLES 6 and 7: Willingnes to pay
*Total sample
*Cost: -WAGE

eststo r0wage, title("Monthly Wage"): clogit sel fulltime_flex parttime_noflex parttime_flex cost, group(id2) cluster(id2) 
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: r0wage


eststo r0hwage, title("Hourly Wage"): clogit sel fulltime_flex parttime_noflex parttime_flex hcost, group(id2) cluster(id2)
wtp hcost fulltime_flex parttime_noflex parttime_flex
estadd WTP: r0hwage

estout r0wage r0hwage using "Table6.tex", replace `opts1' margin 
tablasj3, title(Conditional Logit Coefficients) input(Clogit1) colum(2)
	
estout r0wage r0hwage using "Table7.tex", replace `opts2' 
tablasj4, title(WTP - Monthly vs Hourly Wages) input(WTP1) colum(2)	

/*

gen pval=.
gen tstat=.
gen se=.
gen beta_ftf=.
gen beta_ptnf=.
gen beta_ptf=.
gen wtp_ftf = .
gen wtp_ftf_ll = .
gen wtp_ftf_ul = .

gen wtp_ptnf = .
gen wtp_ptnf_ll = .
gen wtp_ptnf_ul = .

gen wtp_ptf = .
gen wtp_ptf_ll = .
gen wtp_ptf_ul = .


forvalues iteration= 1/1387{
capture clogit sel fulltime_flex parttime_noflex parttime_flex cost if id  == `iteration', group(id)
 matrix theseresults=r(table)
 qui replace beta_ftf=theseresults[1,1] in `iteration' 
 qui replace beta_ptnf=theseresults[1,2] in `iteration' 
 qui replace beta_ptf=theseresults[1,3] in `iteration' 
 wtp cost fulltime_flex parttime_noflex parttime_flex
 matrix wtp=r(wtp)
 qui replace wtp_ftf =wtp[1,1] in `iteration' 
 qui replace wtp_ftf_ll =wtp[2,1] in `iteration' 
 qui replace wtp_ftf_ul =wtp[3,1] in `iteration' 

 qui replace wtp_ptnf =wtp[1,2] in `iteration' 
 qui replace wtp_ptnf_ll =wtp[2,2] in `iteration' 
 qui replace wtp_ptnf_ul =wtp[3,2] in `iteration' 


 qui replace wtp_ptf =wtp[1,3] in `iteration' 
 qui replace wtp_ptf_ll =wtp[2,3] in `iteration' 
 qui replace wtp_ptf_ul =wtp[3,3] in `iteration' 

}



forvalues iteration= 1/1387{
capture clogit sel fulltime_flex parttime_noflex parttime_flex hcost if id  == `iteration', group(id)
 matrix theseresults=r(table)
 qui replace beta_ftf=theseresults[1,1] in `iteration' 
 qui replace beta_ptnf=theseresults[1,2] in `iteration' 
 qui replace beta_ptf=theseresults[1,3] in `iteration' 
 wtp hcost fulltime_flex parttime_noflex parttime_flex
 matrix wtp=r(wtp)
 qui replace wtp_ftf =wtp[1,1] in `iteration' 
 qui replace wtp_ftf_ll =wtp[2,1] in `iteration' 
 qui replace wtp_ftf_ul =wtp[3,1] in `iteration' 

 qui replace wtp_ptnf =wtp[1,2] in `iteration' 
 qui replace wtp_ptnf_ll =wtp[2,2] in `iteration' 
 qui replace wtp_ptnf_ul =wtp[3,2] in `iteration' 


 qui replace wtp_ptf =wtp[1,3] in `iteration' 
 qui replace wtp_ptf_ll =wtp[2,3] in `iteration' 
 qui replace wtp_ptf_ul =wtp[3,3] in `iteration' 

}

preserve
keep id beta_* wtp_*
save WTPIND_HOURLY.dta, replace
restore




preserve

use WTPIND_monthly.dta, clear

winsor2 wtp_ftf wtp_ptf wtp_ptnf, suffix(5) cuts (5 95) trim
winsor2 wtp_ftf wtp_ptf wtp_ptnf, suffix(10) cuts (10 90) trim


twoway (hist wtp_ftf5 ), title(Full-time flex -monthly-)
graph export "figure2a.pdf", as(pdf) replace

twoway (hist wtp_ptnf5 ), title(Part-time no flex -monthly-)
graph export "figure2b.pdf", as(pdf) replace

twoway (hist wtp_ptf5 ), title(Part-time flex -monthly-)
graph export "figure2c.pdf", as(pdf) replace

restore

*/


***********************************************************************************/


*Pantalla 1 vs 4
gen sel4 = seleccion if orden2 == 4
bysort id: egen sel4d = mean(sel4)
label var sel4d "Screen 4"

eststo in1: estpost tab sel4d seleccion if orden2 == 1 & (ciclo == 1 | ciclo == 3 | ciclo ==4)
	
esttab in1 using "In1.tex", cell(b) unstack noobs replace nonum  collabels(none) eqlabels(, lhs("`:variable label sel4d'")) ///
    mtitles("Screen 1")
tabletab, title(Selection Screen 1 vs 4) input(In1) 

*Same analysis without inatentives		
gen inatentas = [sel4d != seleccion] if orden2 ==1 & (ciclo == 1 | ciclo == 3 | ciclo ==4) & sel4d != .
bysort id: egen inatentas2 =  mean(inatentas)


eststo r0wage2, title("Monthly Wage Attentive"): clogit sel fulltime_flex parttime_noflex parttime_flex cost if inatentas2 == 0 , group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: r0wage2

eststo r0hwage2, title("Hourly Wage Attentive"): clogit sel fulltime_flex parttime_noflex parttime_flex hcost if inatentas2 == 0 , group(id2) cluster(id2)
wtp hcost fulltime_flex parttime_noflex parttime_flex
estadd WTP: r0hwage2

estout r0wage r0wage2 r0hwage r0hwage2 using "Clogit2.tex", replace `opts1' margin 
tablasj3, title(Conditional Logit Coefficients) input(Clogit2) colum(5)
	
estout r0wage r0wage2 r0hwage r0hwage2 using "WTP2.tex", replace `opts2' 
tablasj4, title(WTP - Excluding Innatentive) input(WTP2) colum(5)	

*Screen Random Order
eststo in1: estpost tab seleccion pantalla
	
esttab in1 using "In2.tex", cell(b) unstack noobs replace nonum  collabels(none) eqlabels(, lhs("`:variable label Selection'")) ///
    mtitles("Screen")
tabletab, title(Selection by Screen) input(In2) 

eststo r0sub1, title("Screen 1-4"): clogit sel fulltime_flex parttime_noflex parttime_flex cost if pantalla < 4, group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: r0sub1

eststo r0sub2, title("Screen 4-7"): clogit sel fulltime_flex parttime_noflex parttime_flex cost if pantalla > = 4 & pantalla < 7, group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: r0sub2

eststo r0sub3, title("Screen 7-10"): clogit sel fulltime_flex parttime_noflex parttime_flex cost if pantalla > = 7, group(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: r0sub3

estout r0sub1 r0sub2 r0sub3  using "Clogit3.tex", replace `opts1' margin 
tablasj3, title(Conditional Logit Coefficients) input(Clogit3) colum(4)
	
estout r0sub1 r0sub2 r0sub3  using "WTP3.tex", replace `opts2' 
tablasj4, title(WTP by Screen) input(WTP3) colum(4)	

*Within Screen Random Order
tab seleccion orden1

eststo r1a, title("Additional Controls"): clogit sel fulltime_flex parttime_noflex parttime_flex cost first middle , group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: r1a

eststo r1b, title("Additional Controls"): clogit sel fulltime_flex parttime_noflex parttime_flex hcost first middle , group(id2) cluster(id2)
wtp hcost fulltime_flex parttime_noflex parttime_flex
estadd WTP: r1b

estout r0wage r1a r0hwage r1b using "Clogit4.tex", replace `opts1' margin 
tablasj3, title(Conditional Logit Coefficients) input(Clogit4) colum(2)
	
estout r0wage r1a r0hwage r1b using "WTP4.tex", replace `opts2' 
tablasj4, title(WTP - controlling for random order within screen) input(WTP4) colum(2)	

***********************************************************************************/
**** Heterogenous Effects

*Creating Indices
*Need for flexibility

*1.	Numero de hijos
*2.	Dependants (si o no) 
*3.	Commuting time (var continua)
*4.	School holidays (más flexibilidad)


egen hijos_sd = std(hijos)
egen dep_sd = std(dependientes)
egen commute_sd= std(commut_time)
gen holidays = [mes == 7  | mes == 12] if mes != .
replace holidays = 0 if cuidado_alguien == 0
egen holidays_sd = std(holidays)

egen aux = rowmean(hijos_sd dep_sd commute_sd holidays_sd)
egen aux2 = std(aux)
label var aux2 "Standardized values of mean of std variables" 
gen index_flex = [aux2>0]
drop aux aux2

eststo flex1, title("Need for Flexibility"): clogit sel fulltime_flex parttime_noflex parttime_flex cost if index_flex == 1, group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex1 
mat A = r(wtp)

eststo flex2, title("No need for flexibility"): clogit sel fulltime_flex parttime_noflex parttime_flex cost if index_flex == 0, group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex2
mat B = r(wtp)

coefplot (matrix(A[1,]), label(Need for flexibility) ci((A[2,] A[3,]))) ///
 (matrix(B[1,]), label(No need for flexibility) ci((B[2,] B[3,]))),  drop(parttime_flex) xline(0)  xline(0) xscale(range(-100 300)) xlabel(-100(100)300) ylabel(1 "Full-time flex" 2 "Part-time no flex") mlabel format(%9.2g) mlabposition(12) mlabgap(*2)  
graph export "figure4a.pdf", as(pdf) replace


******************************************

*Need for affordability

gen income = 400000 if income_level == 1
replace income = 1000000 if income_level == 5
replace income = 1350000 if income_level == 2
replace income = 2250000 if income_level == 3
replace income = 4000000 if income_level == 4
replace income = 5000000 if income_level == 5

egen income_sd = std(income)

gen yeduc = 0 if educ == 1
replace yeduc = 5 if educ == 2
replace yeduc = 11 if educ == 3
replace yeduc = 12 if educ == 4
replace yeduc = 16 if educ == 5

egen yeduc_sd = std(income)
egen active_sd = std(active)

gen durunemp = 4 if rango_sem_bempleo == 1
replace durunemp = 12.5 if rango_sem_bempleo == 2
replace durunemp = 20.5 if rango_sem_bempleo == 3
replace durunemp = 28.5 if rango_sem_bempleo == 4
replace durunemp = 36.5 if rango_sem_bempleo == 5
replace durunemp = 44.5 if rango_sem_bempleo == 6
replace durunemp = 52.5 if rango_sem_bempleo == 7
replace durunemp = 60.5 if rango_sem_bempleo == 8
replace durunemp = 68.5 if rango_sem_bempleo == 9
replace durunemp = 76.5 if rango_sem_bempleo == 10
replace durunemp = 92.5 if rango_sem_bempleo == 12
replace durunemp = 96 if rango_sem_bempleo == 13


egen durunemp_sd = std(1/durunemp)

egen salario_sd = std(salario)

egen aux1 = rowmean(income_sd yeduc_sd active_sd salario_sd durunemp_sd)
egen aux2 = std(aux1)
label var aux2 "Standardized values of mean of std variables" 
gen index_afford = [aux2 < 0]
drop aux1 aux2

eststo flex1, title("Low Affordability"): clogit sel fulltime_flex parttime_noflex parttime_flex cost if index_afford == 1, group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex1 
mat A = r(wtp)

eststo flex2, title("High Affordability"): clogit sel fulltime_flex parttime_noflex parttime_flex cost if index_afford == 0, group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex2
mat B = r(wtp)


coefplot (matrix(A[1,]), label(Low Affordability) ci((A[2,] A[3,]))) ///
 (matrix(B[1,]), label(High Affordability) ci((B[2,] B[3,]))),  drop(parttime_flex) xline(0)  xline(0) xscale(range(-100 300)) xlabel(-100(100)300) ylabel(1 "Full-time flex" 2 "Part-time no flex") mlabel format(%9.2g) mlabposition(12) mlabgap(*2)  
graph export "figure4b.pdf", as(pdf) replace

******************************************
***********************************************************************************/
*Preferences for Flexibility
eststo flex1, title("Flex Prefered"): clogit sel fulltime_flex parttime_noflex parttime_flex cost if prefer_job == 1, group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex1 
mat A = r(wtp)

eststo flex2, title("Flex Any"): clogit sel fulltime_flex parttime_noflex parttime_flex cost if prefer_job_any == 1, group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex2
mat B = r(wtp)

eststo flex3, title("Flex None"): clogit sel fulltime_flex parttime_noflex parttime_flex cost if prefer_job_none == 1, group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex3
mat C = r(wtp)


coefplot (matrix(A[1,]), label(Top Priority) ci((A[2,] A[3,]))) (matrix(B[1,]), label(Priority 2-3) ci((B[2,] B[3,]))) (matrix(C[1,]), label(Not a Priority) ci((C[2,] C[3,]))), drop(parttime_flex)  xline(0) xscale(range(-300 300)) xlabel(-300(100)500) ylabel(1 "Full-time flex" 2 "Part-time no flex" ) mlabel format(%9.2g) mlabposition(12) mlabgap(*2)  
graph export "figure5.pdf", as(pdf) replace


***********************************************************************************/
*Sectors


eststo flex1, title("Sector 1"): clogit sel fulltime_flex parttime_noflex parttime_flex cost if area == 1, group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex1 
mat A = r(wtp)

eststo flex2, title("Sector 3 "): clogit sel fulltime_flex parttime_noflex parttime_flex cost if area == 4, group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex2
mat B = r(wtp)

eststo flex2, title("Sector 15 "): clogit sel fulltime_flex parttime_noflex parttime_flex cost if area == 15, group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex2
mat C = r(wtp)


coefplot (matrix(A[1,]), drop(parttime_flex) label(Finance and Admin) ci((A[2,] A[3,]))) ///
 (matrix(B[1,]), drop(parttime_flex) label(Education) ci((B[2,] B[3,]))) ///
 (matrix(C[1,]), drop(parttime_flex) label(Secretary/clerk) ci((C[2,] C[3,]))) , xline(0) xscale(range(-100 500)) xlabel(-100(100)500) ylabel(1 "Full-time flex" 2 "Part-time no flex") mlabel format(%9.2g) mlabposition(12) mlabgap(*2)  
graph export "figure6a.pdf", as(pdf) replace


 
***

eststo flex1, title("Sector 4"): clogit sel fulltime_flex parttime_noflex parttime_flex cost if area == 3, group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex1 
mat A = r(wtp)

eststo flex2, title("Sector 13 "): clogit sel fulltime_flex parttime_noflex parttime_flex cost if area == 13, group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex2
mat B = r(wtp)

eststo flex2, title("Sector 16 "): clogit sel fulltime_flex parttime_noflex parttime_flex cost if area == 16, group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex2
mat C = r(wtp)

eststo flex2, title("Sector 17 "): clogit sel fulltime_flex parttime_noflex parttime_flex cost if area == 17, group(id2) cluster(id2)
wtp cost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex2
mat D = r(wtp)

coefplot (matrix(A[1,]), drop(parttime_flex) label(Sales) ci((A[2,] A[3,]))) ///
 (matrix(B[1,]), drop(parttime_flex) label(Health) ci((B[2,] B[3,])))  (matrix(C[1,]), drop(parttime_flex) label(Customer service) ci((C[2,] C[3,]))) ///
 (matrix(D[1,]), drop(parttime_flex) label(General services) ci((D[2,] D[3,]))) ,  xline(0) xscale(range(-100 500)) xlabel(-100(100)500) ylabel(1 "Full-time flex" 2 "Part-time no flex") mlabel format(%9.2g) mlabposition(12) mlabgap(*2)  
graph export "figure6b.pdf", as(pdf) replace
tex \includegraphics[scale=0.5]{H13.pdf}

***********************
*Appendix

eststo flex1, title("Need for Flexibility"): clogit sel fulltime_flex parttime_noflex parttime_flex hcost if index_flex == 1, group(id2) cluster(id2)
wtp hcost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex1 
mat A = r(wtp)

eststo flex2, title("No need for flexibility"): clogit sel fulltime_flex parttime_noflex parttime_flex hcost if index_flex == 0, group(id2) cluster(id2)
wtp hcost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex2
mat B = r(wtp)


coefplot (matrix(A[1,]), label(Need for flexibilility) ci((A[2,] A[3,]))) ///
 (matrix(B[1,]), label(No need for flexibility) ci((B[2,] B[3,]))),  drop(parttime_flex) xline(0) xscale(range(-1 1)) xlabel(-1(0.5)1.5) ylabel(1 "Full-time flex" 2 "Part-time no flex") mlabel format(%9.2g) mlabposition(12) mlabgap(*2)  
graph export "figureApp2a.pdf", as(pdf) replace


eststo flex1, title("Low Affordability"): clogit sel fulltime_flex parttime_noflex parttime_flex hcost if index_afford == 1, group(id2) cluster(id2)
wtp hcost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex1 
mat A = r(wtp)

eststo flex2, title("High Affordability"): clogit sel fulltime_flex parttime_noflex parttime_flex hcost if index_afford == 0, group(id2) cluster(id2)
wtp hcost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex2
mat B = r(wtp)

coefplot (matrix(A[1,]), label(Low Affordability) ci((A[2,] A[3,]))) ///
 (matrix(B[1,]), label(High Affordability) ci((B[2,] B[3,]))),  drop(parttime_flex) xline(0) xscale(range(-1 1)) xlabel(-1(0.5)1.5) ylabel(1 "Full-time flex" 2 "Part-time no flex") mlabel format(%9.2g) mlabposition(12) mlabgap(*2)  
graph export "figureApp2b.pdf", as(pdf) replace

*Preferences for Flexibility
eststo flex1, title("Flex Prefered"): clogit sel fulltime_flex parttime_noflex parttime_flex hcost if prefer_job == 1, group(id2) cluster(id2)
wtp hcost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex1 
mat A = r(wtp)

eststo flex2, title("Flex Any"): clogit sel fulltime_flex parttime_noflex parttime_flex hcost if prefer_job_any == 1, group(id2) cluster(id2)
wtp hcost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex2
mat B = r(wtp)

eststo flex3, title("Flex None"): clogit sel fulltime_flex parttime_noflex parttime_flex hcost if prefer_job_none == 1, group(id2) cluster(id2)
wtp hcost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex3
mat C = r(wtp)

coefplot (matrix(A[1,]), label(Top Priority) ci((A[2,] A[3,]))) (matrix(B[1,]), label(Priority 2-3) ci((B[2,] B[3,]))) (matrix(C[1,]), label(Not a Priority) ci((C[2,] C[3,]))), drop(parttime_flex) xline(0) xscale(range(-1 1)) xlabel(-1(0.5)2) ylabel(1 "Full-time flex" 2 "Part-time no flex") mlabel format(%9.2g) mlabposition(12) mlabgap(*2)  
graph export "figureApp3.pdf", as(pdf) replace


***

eststo flex1, title("Sector 1"): clogit sel fulltime_flex parttime_noflex parttime_flex hcost if area == 1, group(id2) cluster(id2)
wtp hcost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex1 
mat A = r(wtp)

eststo flex2, title("Sector 3 "): clogit sel fulltime_flex parttime_noflex parttime_flex hcost if area == 4, group(id2) cluster(id2)
wtp hcost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex2
mat B = r(wtp)

eststo flex2, title("Sector 15 "): clogit sel fulltime_flex parttime_noflex parttime_flex hcost if area == 15, group(id2) cluster(id2)
wtp hcost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex2
mat C = r(wtp)


coefplot (matrix(A[1,]), label(Finance and Admin) ci((A[2,] A[3,]))) ///
 (matrix(B[1,]), label(Education) ci((B[2,] B[3,]))) ///
 (matrix(C[1,]), label(Secretary/clerk) ci((C[2,] C[3,]))) ,drop(parttime_flex) xline(0) xscale(range(-1 1)) xlabel(-1(0.5)2) ylabel(1 "Full-time flex" 2 "Part-time no flex") mlabel format(%9.2g) mlabposition(12) mlabgap(*2)  
graph export "figureApp4a.pdf", as(pdf) replace
tex \includegraphics[scale=0.5]{H12hourly.pdf}

**

eststo flex1, title("Sector 4"): clogit sel fulltime_flex parttime_noflex parttime_flex hcost if area == 3, group(id2) cluster(id2)
wtp hcost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex1 
mat A = r(wtp)

eststo flex2, title("Sector 13 "): clogit sel fulltime_flex parttime_noflex parttime_flex hcost if area == 13, group(id2) cluster(id2)
wtp hcost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex2
mat B = r(wtp)

eststo flex2, title("Sector 16 "): clogit sel fulltime_flex parttime_noflex parttime_flex hcost if area == 16, group(id2) cluster(id2)
wtp hcost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex2
mat C = r(wtp)

eststo flex2, title("Sector 17 "): clogit sel fulltime_flex parttime_noflex parttime_flex hcost if area == 17, group(id2) cluster(id2)
wtp hcost fulltime_flex parttime_noflex parttime_flex
estadd WTP: flex2
mat D = r(wtp)

coefplot (matrix(A[1,]), label(Sales) ci((A[2,] A[3,]))) ///
 (matrix(B[1,]), label(Health) ci((B[2,] B[3,])))  (matrix(C[1,]), label(Customer service) ci((C[2,] C[3,]))) ///
 (matrix(D[1,]), label(General services) ci((D[2,] D[3,]))) ,drop(parttime_flex) xline(0) xscale(range(-1 1)) xlabel(-1(0.5)2) ylabel(1 "Full-time flex" 2 "Part-time no flex") mlabel format(%9.2g) mlabposition(12) mlabgap(*2)  
graph export "figureApp4b.pdf", as(pdf) replace
tex \includegraphics[scale=0.5]{H13hourly.pdf}



***Testing differences in WTPs *****

cap pr drop wtpcompare
pr define wtpcompare
syntax varlist  [, cond1(string) cond2(string) ]
qui{
clogit sel fulltime_flex parttime_noflex parttime_flex cost if `cond1', group(id2) 
est store m1
clogit sel fulltime_flex parttime_noflex parttime_flex cost if `cond2', group(id2) 
est store m2
suest m1 m2, vce(cluster id2)
}
foreach var of local varlist{
qui{
scalar WTP1 = (-_b[m1_sel:`var']/_b[m1_sel:cost]) 
scalar WTP2 = (-_b[m2_sel:`var']/_b[m2_sel:cost])

testnl (-_b[m1_sel:`var']/_b[m1_sel:cost]) = (-_b[m2_sel:`var']/_b[m2_sel:cost]) 
return list
scalar Chi_fig = r(chi2)
scalar p_fig = r(p)
}
di "`var'" "," WTP1 "," WTP2 "," Chi_fig "," p_fig
}
end 

*Figure4a
wtpcompare fulltime_flex parttime_noflex, cond1(index_flex == 1) cond2(index_flex== 0) 
*Figure4b
wtpcompare fulltime_flex parttime_noflex, cond1(index_afford == 1) cond2(index_afford== 0) 
*Figure5a
wtpcompare fulltime_flex parttime_noflex, cond1(prefer_job == 1) cond2(prefer_job_none== 1) 
*Figure5b
wtpcompare fulltime_flex parttime_noflex, cond1(prefer_job_any == 1) cond2(prefer_job_none== 1) 
*Figure6 
gen sector_flex = [area == 1| area == 4 |area == 15] if area != .
gen sector_noflex = [area == 3 | area == 13 | area == 16 |area == 17] if area != . 
wtpcompare fulltime_flex parttime_noflex, cond1(sector_flex == 1) cond2(sector_noflex== 1) 



**********************************************************************************





